package com.example.shangjinlieren.fractionPage;

import com.example.shangjinlieren.ResourceTable;
import com.example.shangjinlieren.tabbar.fraction.BaseFraction;
import com.example.shangjinlieren.tabbar.fraction.FractionUtil;
import com.example.shangjinlieren.tabbar.model.BottomNavViewModel;
import com.example.shangjinlieren.utils.RpxUtil;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.LayoutAlignment;
import ohos.app.Context;

public class MoneyList  extends BaseFraction {
    Context context;
    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        String action = intent.getAction();
        this.context = container.getContext();
        Component MoneyListBody =scatter.parse(ResourceTable.Layout_money_list
                , null, false);
        DirectionalLayout componentById =(DirectionalLayout) MoneyListBody.findComponentById(ResourceTable.Id_moneylistbody);
        Button button = new Button(this.context);
        button.setWidth(ComponentContainer.LayoutConfig.MATCH_CONTENT);
        button.setHeight(ComponentContainer.LayoutConfig.MATCH_CONTENT);
        ShapeElement shapeElement = new ShapeElement();
        RgbColor rgbColor = new RgbColor(1, 255, 255);
        shapeElement.setRgbColor(rgbColor);
        shapeElement.setCornerRadius(RpxUtil.rpx(23,this.context));
        button.setPadding((int) RpxUtil.rpx(17,this.context),
                (int) RpxUtil.rpx(11,this.context),
                (int) RpxUtil.rpx(17,this.context),
                (int) RpxUtil.rpx(11,this.context)
                );

        button.setBackground(shapeElement);
        button.setText("跳转详情页");

        button.setClickedListener(listener->{
            //目的
            intent.setAction("action.list.detail");  //关键是配置文件里配置action和Ability里注册路由
            startAbility(intent,1);

        });
        button.setTextSize((int) RpxUtil.rpx(24,this.context));
        componentById.setAlignment(LayoutAlignment.CENTER);
        componentById.addComponent(button);
        return MoneyListBody;
    }


    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
    }
    public void demo(LayoutScatter scatter, ComponentContainer container, Intent intent){

    }

    @Override
    protected void onActive() {
        super.onActive();
    }

    @Override
    protected void onForeground(Intent intent) {
        System.out.println("MoneyList+onForeground");
        super.onForeground(intent);
    }

    @Override
    protected void onInactive() {
        super.onInactive();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public int getUIContent() {
        return ResourceTable.Layout_money_list;
    }

    @Override
    public void initComponent() {

    }
}
